package com.toymate.ai.llm;

import cn.hutool.extra.spring.SpringUtil;
import com.toymate.ai.llm.model.coze.CozeLlmService;
import com.toymate.ai.llm.model.dify.DifyLlmService;
import com.toymate.common.constant.AiConstant;
import com.toymate.modules.iot.entity.IotRole;
import com.toymate.modules.iot.service.IotRoleService;

/**
 * LLMFactory
 *
 * @author weirdor (179946422@qq.com)
 * @version v1.0.0
 */
public final class LLMFactory {

    private static IotRoleService iotRoleService;

    static {
        LLMFactory.iotRoleService = SpringUtil.getBean(IotRoleService.class);
    }

    public static AbstractLlmService build(IotRole role) {
        //根据角色ID查询角色信息
        LlmConfig config = iotRoleService.getValueObject(role.getRoleId(), "llm", LlmConfig.class);
        if (AiConstant.llmService.DIFY.getValue().equals(config.getLlmType())) {
            return new DifyLlmService(config, role);
        }
        if (AiConstant.llmService.COUZE.getValue().equals(config.getLlmType())) {
            return new CozeLlmService(config, role);
        }
        return null;
    }
}
